package com.ruoyi.bussiness.service.impl;

import java.util.List;
import com.ruoyi.bussiness.domain.PlanDetailsRsp;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.bussiness.mapper.CcyTradeSuccessMapper;
import com.ruoyi.bussiness.domain.CcyTradeSuccess;
import com.ruoyi.bussiness.service.ICcyTradeSuccessService;

/**
 * 成交订单Service业务层处理
 * 
 * @author wzy
 * @date 2025-10-21
 */

@Slf4j
@Service
public class CcyTradeSuccessServiceImpl implements ICcyTradeSuccessService 
{
    @Autowired
    private CcyTradeSuccessMapper ccyTradeSuccessMapper;

    /**
     * 查询成交订单
     * 
     * @param id 成交订单主键
     * @return 成交订单
     */
    @Override
    public CcyTradeSuccess selectCcyTradeSuccessById(Long id)
    {
        return ccyTradeSuccessMapper.selectCcyTradeSuccessById(id);
    }

    /**
     * 查询成交订单列表
     * 
     * @param ccyTradeSuccess 成交订单
     * @return 成交订单
     */
    @Override
    public List<CcyTradeSuccess> selectCcyTradeSuccessList(CcyTradeSuccess ccyTradeSuccess)
    {
        return ccyTradeSuccessMapper.selectCcyTradeSuccessList(ccyTradeSuccess);
    }

    /**
     * 新增成交订单
     * 
     * @param ccyTradeSuccess 成交订单
     * @return 结果
     */
    @Override
    public int insertCcyTradeSuccess(CcyTradeSuccess ccyTradeSuccess)
    {
        return ccyTradeSuccessMapper.insertCcyTradeSuccess(ccyTradeSuccess);
    }

    /**
     * 修改成交订单
     * 
     * @param ccyTradeSuccess 成交订单
     * @return 结果
     */
    @Override
    public int updateCcyTradeSuccess(CcyTradeSuccess ccyTradeSuccess)
    {
        return ccyTradeSuccessMapper.updateCcyTradeSuccess(ccyTradeSuccess);
    }

    /**
     * 批量删除成交订单
     * 
     * @param ids 需要删除的成交订单主键
     * @return 结果
     */
    @Override
    public int deleteCcyTradeSuccessByIds(Long[] ids)
    {
        return ccyTradeSuccessMapper.deleteCcyTradeSuccessByIds(ids);
    }

    /**
     * 删除成交订单信息
     * 
     * @param id 成交订单主键
     * @return 结果
     */
    @Override
    public int deleteCcyTradeSuccessById(Long id)
    {
        return ccyTradeSuccessMapper.deleteCcyTradeSuccessById(id);
    }


    @Override
    public List<PlanDetailsRsp> selectTotal(CcyTradeSuccess ccyTradeSuccess) {
        List<PlanDetailsRsp> list = ccyTradeSuccessMapper.selectTotal(ccyTradeSuccess);
        double total = 0;
        for (PlanDetailsRsp planDetailsRsp : list) {
            total += planDetailsRsp.get最终收益();
        }
        PlanDetailsRsp rsp = new PlanDetailsRsp();
        rsp.set方案编号("总体");
        rsp.set最终收益(Double.parseDouble(String.format("%.1f",total)));
        list.add(rsp);
        log.info("添加集合后:返回报文:{}", list);
        return list;
    }
}
